package com.maijinjie.common.aop;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;

import com.maijinjie.common.aop.common.BasicAspect;

public class TestAspect {
    public void doAfter(JoinPoint jp) {
        System.out.println("结束执行 method: "
                + jp.getTarget().getClass().getName() + "."
                + jp.getSignature().getName());
        System.out.println("=============================================================");
    }
    public Object doAround(ProceedingJoinPoint pjp) throws Throwable {
        long time = System.currentTimeMillis();
        Object retVal = pjp.proceed();
        time = System.currentTimeMillis() - time;
        System.out.println("执行完毕 time: " + time + " ms");
        
        
        
        HttpServletRequest request = SysContent.getRequest();  
//        HttpServletResponse response = SysContent.getResponse();  
//        HttpSession session = SysContent.getSession();  
        
        String param = request.getParameter("userName");
        System.out.println(param);
        return retVal;
    }
    public void doBefore(JoinPoint jp) {
        System.out.println("开始执行 method: "
                + jp.getTarget().getClass().getName() + "."
                + jp.getSignature().getName());
    }
    public void doThrowing(JoinPoint jp, Throwable ex) {
        System.out.println("异常 method " + jp.getTarget().getClass().getName()
                + "." + jp.getSignature().getName() + " throw exception");
        System.out.println(ex.getMessage());
    }

    private void sendEx(String ex) {
        //TODO 发送短信或邮件提醒
    }
}